<template>
  <el-dialog
    v-el-drag-dialog
    title="转派"
    :visible.sync="visible"
    width="500px"
    @closed="reset"
  >
    <el-form label-position="right">
      <el-form-item label="处理人：" label-width="90px">
        <el-select v-model="targetUserId" filterable="true" placeholder="请选择处理人">
          <el-option v-for="(item) in userData" :key="item.userId" :label="item.userName" :value="item.userId" />
        </el-select>
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm()">
        确定
      </el-button>
      <el-button @click="visible = false">
        关闭
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { csDeliverUserList, updateOperator } from '@/api'
  export default {
    name: 'transfer',
    props: {
      parentFetchData: {
        type: Function
      }
    },
    data() {
      return {
        visible: false,
        targetUserId: '',
        remark: '',
        userData: []
      }
    },
    methods: {
      open(codes, checkIds, row) {
        this.visible = true
        this.codes = codes
        this.checkIds = checkIds
        this.recheckListUser(row)
      },
      async recheckListUser(row) {
        const res = await csDeliverUserList({ utype: '16384' })
        console.log(res)
        this.userData = res.data
        if (this.checkIds.length === 1) {
          this.targetUserId = row && row.lastCheckUserId ? row.lastCheckUserId : ''
        }
      },
      async confirm() {
        if (!this.targetUserId) {
          this.$message.warning('请选择处理人')
          return
        }
        const user = this.userData.filter((item) => item.userId === this.targetUserId)
        const query = {
          codes: this.codes,
          targetUserId: this.targetUserId + ';' + user[0].userName
        }
        const res = await updateOperator(query)
        if (res.status === 200) {
          this.visible = false
          this.parentFetchData({})
          this.$message.success('操作成功')
        }
      },
      reset() {
        this.targetUserId = ''
      }
    }
  }
</script>
<style lang="scss" scoped>
.remark {
  display: flex;
  & /deep/ .el-form-item__content {
    width: 100%;
    margin-left: 0 !important;
  }
}
</style>
